package topcoder;

import java.util.Arrays;

public class SRMCodingPhase {

	private int _countScore(int[] points, int[] skills, int luck, int score, boolean[] done, int t){
		int[] r = new int[3];
		for(int i=0; i<3; i++){
			r[i] = score;
			if(!done[i] && (t+luck)>=skills[i]){
				done[i] = true;
				int luck2, score2, t2;
				if(luck>0){
					if(luck<skills[i]){
						luck2 = 0;
						score2 = score + points[i] - (int)Math.pow(2, i+1) * (skills[i] - luck);
						t2 = t - skills[i] + luck;
					}
					else{
						luck2 = luck - skills[i] + 1;
						score2 = score + points[i] - (int)Math.pow(2, i+1);
						t2 = t - 1;
					}
				}
				else{
					luck2 = 0;
					score2 = score + points[i] - (int)Math.pow(2, i+1) * skills[i];
					t2 = t - skills[i];
				}
				r[i] = _countScore(points, skills, luck2, score2, done, t2);
				done[i] = false;
			}
		}
		return Math.max(r[0], Math.max(r[1], r[2]));
	}
	
	public int countScore(int[] points, int[] skills, int luck){
		boolean[] done = new boolean[3];
		Arrays.fill(done, false);
		return _countScore(points, skills, luck, 0, done, 75);
	}
	
	public static void main(String[] args) {
		SRMCodingPhase scp = new SRMCodingPhase();
		int[] a = {250, 450, 1100};
		int[] b = {50, 70, 90};
		System.out.println(scp.countScore(a, b, 20));
	}
}
